package com.vclee.fast.utils;


import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 分布式自增工具类
 */
public class SnowUtils {
    private static final AtomicInteger min;
    private static final AtomicLong max;

    static {
        Random random = new Random();
        int prefix = random.nextInt(43)+57;
        int end = (int) (System.currentTimeMillis()/(10*60*60*24));
        min = new AtomicInteger(Integer.parseInt(prefix+""+end));
        max = new AtomicLong(Long.parseLong((random.nextInt(51)+49)+""+System.currentTimeMillis()));
    }

    /**
     * 获取15位不重复Key
     * @return String
     */
    public static Long getBigKey() {
        return max.getAndIncrement();
    }

    /**
     * 获取11位不重复Key
     * @return String
     */
    public static String getStrKey() {
        return 7+Long.toUnsignedString(getBigKey(),32).toUpperCase();
    }

    public static String key32Str(){
        return UUID.randomUUID().toString().replaceAll("-","").toUpperCase();
    }

    public static Integer getIntKey(){
        return min.getAndIncrement();
    }

}
